-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interactivity API: Fix context object proxy references #59553
Interactivity API: Fix context object proxy references #59553
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +67 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
It is my understanding that this PR ensures that the contract provided by the Interactivity API is maintained. Without this references to objects in context could change and this would be unexpected based on the terms of the API. Therefore this PR is critical to the proper functioning of the Interactivity API which is due to be stablised in WP 6.5. For this reason I believe this PR should be included during the RC period. |
I just cherry-picked this PR to the pick/wp-65-rc-2 branch to get it included in the next release: dcce36d |
* Add failing test * Fix returned proxy reference * Add more reference tests * Fix assignment of context objects * Update comment * Update changelog Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org>
* Add failing test * Fix returned proxy reference * Add more reference tests * Fix assignment of context objects * Update comment * Update changelog Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org>
What?
Fixes a bug with context references not being preserved.
When reading a property from the context whose value is an object, the current implementation wraps that object with a
Proxy
to handle context inheritance. That "proxification" happens every time the property is accessed, instantiating a newProxy
, thus changing the returned reference.For instance, the following state getter accessing the context always returns false.
Why?
Context properties should allow storing references to other context objects. This is something that Interactive Block developers would expect.
How?
Using some
WeakMap
instances to keep track of the objects inside the context to always return the same proxy.